package hiatao.puzzle.fragment;

import haitao.puzzle.R;
import hiatao.puzzle.activity.UserActivity;
import hiatao.puzzle.adapter.ListUserAdapter;
import hiatao.puzzle.config.URLS;
import hiatao.puzzle.entity.User;
import hiatao.puzzle.utils.Tools;
import hiatao.puzzle.widget.XListView;
import java.util.ArrayList;
import java.util.List;

import com.desmond.parallaxheaderviewpager.TestActivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class RankFriendsFragment extends Fragment{

	
	private View rootView;
    private XListView listView = null;
    private ListUserAdapter adapter;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		rootView = inflater.inflate(R.layout.xlistview, container, false);
		findView();
		init();
		return rootView;
	}

	private void init() {
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				Intent intent = new Intent();
				intent.setClass(getActivity(), TestActivity.class);
				//intent.setClass(getActivity(), UserActivity.class);
				intent.putExtra("SELF", false);
				intent.putExtra("USER", (User)adapter.getItem(position-2));
				getActivity().startActivity(intent);
			}
		});
	}

	private void findView() {
		listView = (XListView) rootView.findViewById(R.id.listview);
		View header = getActivity().getLayoutInflater().inflate(R.layout.rank_header, null);
		TextView tv =(TextView) header.findViewById(R.id.rank_tv);
		tv.setText("你在当前朋友玩家排名125名");
		listView.addHeaderView(header);
		adapter = new ListUserAdapter(getActivity(), null);
		listView.setAdapter(adapter);
		listView.setPullRefreshEnable(false);
		listView.setPullLoadEnable(false);
		adapter.appendToList(testData());
	}
	private List<User> testData() {
		List<User> userList = new ArrayList<User>();
		User u1= new User();
		u1.setName("Yoohoo");
		u1.setIntro("跳出来看自己");
		u1.setHeadUrl(URLS.BASE_USER+8+".png");
		u1.setFocus(false);
		u1.setZuanNum(100);
		userList.add(u1);
		User u2= new User();
		u2.setName("阿门");
		u2.setIntro(" 如果可以，我想做个梦");
		u2.setHeadUrl(URLS.BASE_USER+9+".png");
		u2.setFocus(true);
		userList.add(u2);
		u2.setZuanNum(98);
		User u3= new User();
		u3.setName("奈何.");
		u3.setIntro(" 没那么简单");
		u3.setHeadUrl(URLS.BASE_USER+10+".png");
		u3.setFocus(true);
		u3.setZuanNum(96);
		userList.add(u3);
		
		User u4= new User();
		u4.setName("子意");
		u4.setIntro("做更好的自己");
		u4.setHeadUrl(URLS.BASE_USER+11+".png");
		u4.setFocus(true);
		u4.setZuanNum(94);
		userList.add(u4);
		
		User u5= new User();
		u5.setName("刘杨");
		u5.setIntro("拼图达人是我，不服来拼。");
		u5.setHeadUrl(URLS.BASE_USER+12+".png");
		u5.setFocus(true);
		u5.setZuanNum(90);
		userList.add(u5);
		
		
		User u6= new User();
		u6.setName("桑桑尼");
		u6.setIntro(" 微风拂面，永失吾王");
		u6.setHeadUrl(URLS.BASE_USER+13+".png");
		u6.setFocus(true);
		u6.setZuanNum(88);
		userList.add(u6);
		
		User u7= new User();
		u7.setName("牛魔王函๑");
		u7.setIntro("毕竟故事还长不要一个人急着去远方");
		u7.setHeadUrl(URLS.BASE_USER+14+".png");
		u7.setFocus(true);
		u7.setZuanNum(86);
		userList.add(u7);
		

		User u8= new User();
		u8.setName("Guan");
		u8.setIntro("把时间用在思考上是最能节省时间的事情");
		u8.setHeadUrl(URLS.BASE_USER+19+".png");
		u8.setFocus(true);
		u8.setZuanNum(85);
		userList.add(u8);
		
		
		User u9= new User();
		u9.setName("潘其标");
		u9.setIntro("生活是一种绵延不绝的渴望，渴望不断上升，变得更伟大而高贵");
		u9.setHeadUrl(URLS.BASE_USER+20+".png");
		u9.setFocus(true);
		u9.setZuanNum(82);
		userList.add(u9);
		
		User u10= new User();
		u10.setName("轻轨");
		u10.setIntro("最成功的说谎者是那些使最少量的谎言发挥最大的作用的人");
		u10.setHeadUrl(URLS.BASE_USER+21+".png");
		u10.setFocus(true);
		u10.setZuanNum(80);
		userList.add(u10);
		
		return userList;
	}
}
